﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.Model;

/// <summary>
/// 自由接单+6元分开统计时间段管理
/// </summary>
public partial class qy_54tss_Admin_activeindexlinklist_freehiftslist : System.Web.UI.Page
{
    Freeshifts dal = new Freeshifts();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            getItem();
        }
    }

    protected void getItem()
    {
        IList<FreeshiftsInfo> list = dal.GetList(100, 1, " 1=1", "reveint1", 1);
        rptsubItem.DataSource = list;
        rptsubItem.DataBind();
        CacheHelper.FreeshiftsClear();
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            if (dal.DelList(e.CommandArgument.ToString()) > 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除成功！');init();");
                getItem();
            }
            else
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除失败，请重试！');init();");
            }
        }
    }

    protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        rptsubItem.EditIndex = e.NewEditIndex;
        getItem();
    }

    protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        rptsubItem.EditIndex = -1;
        getItem();
    }

    protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = Convert.ToInt32(((Label)rptsubItem.Rows[e.RowIndex].FindControl("lb_id")).Text.Trim());

        FreeshiftsInfo info = dal.GetModel(id);
        info.title = ((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbtitle")).Text;
    
        info.reveint1 = Convert.ToInt32(((TextBox)rptsubItem.Rows[e.RowIndex].FindControl("tbreveint1")).Text);
        info.reveint2 = 0;
     
        if (dal.Update(info) > 0)
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑成功！');init();");
            getItem();
        }
        else
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('编辑失败，请重试！');init();");
        }
        rptsubItem.EditIndex = -1;
        getItem();
    }

    protected void btSave_Click(object sender, EventArgs e)
    {
        FreeshiftsInfo info = new FreeshiftsInfo();
        info.title = WebUtility.InputText(tbtitle.Text);
        info.starttime = DateTime.Now;
        info.endtime = DateTime.Now;
        info.workhours = 0;
        info.salary = 0;
        info.reveint1 = Convert.ToInt32(WebUtility.InputText(reveint1.Text));
        info.reveint2 = 0;
        info.revevar1 = "";
        info.revevar2 = "";
        info.revefloat = 0;
        if (dal.Add(info) > 0)
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('添加成功！');init();");
            getItem();
        }
        else
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('添加失败，请重试！');init();");
        }

    }
}

